using System;
using System.IO;
using XTCast.Mp3.Encode;
using XTCast.Mp3;
using TerastarLib.Utils;

namespace XTCast.Radio
{
	/// <summary>
	/// Summary description for SilenceDJ.
	/// </summary>
	public class SilenceDJ:DJ
	{

		Buffer silBuffer;
		public SilenceDJ(Station station, BufferManager bm, StationConfig Config):base(station,bm,Config) {
			FifoStream fs = new FifoStream();
			Mp3Writer mp3Bin = new Mp3Writer(fs,new Wave.WaveFormat(Config.Format.SampleRate,16,Config.Format.Channels),(uint)Config.Format.Bitrate/1000);
			mp3Bin.Write(new Byte[mp3Bin.GetOptimalBufferSize()*8]);
			mp3Bin.Close();
			MP3FrameReader mp3fs = new MP3FrameReader(fs);
			silBuffer = bm.LoadBuffer(mp3fs,Track.Empty);
			mp3Bin.Close();
			fs.Close();
		}

		public override TimeSpan Position 
		{
			get { return TimeSpan.Zero;}
			set {}
		}

		public Buffer SilentBuf {
			get {
				return silBuffer;
			}
		}

		public override void Start() {
		}

		public override void Skip(TimeSpan ts) {
		}

		public void PlaySilence() {
			while (bm.Fill)
				bm.Add(silBuffer.Clone());
		}

		public int PlaySilence(int millis) {
			int i;
			for (i=0;i<millis;i += silBuffer.LengthMillis) {
				bm.Add(silBuffer.Clone());
			}
			return i;
		}
	}
}
